/*
 * @Author: your name
 * @Date: 2021-12-18 22:26:15
 * @LastEditTime: 2021-12-22 21:48:52
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \am\am-server\app\controller\student.js
 */

const { Controller } = require('egg');
const Message = require('../utils/Message')

/**
 * @Controller student-controller:学生相关接口
*/
class StudentController extends Controller {

    /**
   * @Router get /student/findstudentAll
   * @summary 获取所有学生信息
   * @apikey
  */

     async findstudentAll () {
      const { ctx, service } = this
      const students = await service.student.findstudentAll()
      ctx.body = Message.success(students)
    }
  
  /**
   * @Router get /student/pageQuery
   * @summary 分页查询学生信息
   * @request query string *page
   * @request query string *pageSize
   * @apikey
  */
  async pageQuery () {
    console.log('====');
    const { ctx, service } = this
    // 接受用户请求 
    // 获取用户参数 ctx.query 
    // 调用service查询
    const studentsVM = await service.student.pageQuery(ctx.query)
    ctx.body = Message.success(studentsVM)
  }

  /**
   * @Router post /student/saveOrUpdate
   * @summary 保存或修改学生信息
   * @request query number id
   * @request query string *no
   * @request query string *name
   * @apikey
  */
   async saveOrUpdate () {
    const { ctx, service } = this
    // 接受用户请求 
    // 获取用户参数 ctx.query 
    // 调用service查询
    await service.student.saveOrUpdate(ctx.query)
    ctx.body = Message.success("操作成功")
  }

   /**
   * @Router post /student/saveOrUpdate2
   * @summary 保存或修改学生信息，使用json格式
   * @request body studentVM
   * @apikey
  */
    async saveOrUpdate2 () {
      const { ctx, service } = this
      // 接受用户请求 
      // 获取用户参数 ctx.query 
      // 调用service查询
      await service.student.saveOrUpdate(ctx.request.body)
      ctx.body = Message.success("操作成功")
    }

/**
   * @Router delete /student/deletestudentByno
   * @summary 根据no删除学生信息
   * @request query string *no 学生no
   * @apikey
  */

async deletestudentByno () {
  const { ctx, service } = this
  ctx.validate({
    no: 'string'
  }, ctx.query)
  await service.student.deletestudentByno(ctx.query.no)
  ctx.body = Message.success('删除成功')
  }

  /**
  * @Router get /student/findByno
  * @summary 根据学号no查询学生信息
  * @request query string *no 学号no
  * @apikey
 */
   async findByno () {
    const { ctx, service } = this
    ctx.validate({
      no: 'string'
    }, ctx.query)
    const nodata = await service.student.findByno(ctx.query.no)
    ctx.body = Message.success(nodata)
  }
}

module.exports = StudentController;